import { getCartTotalNum } from '@/api/cart'
// import { Message } from 'element-ui'

// Notification({
//   title: '成功',
//   message: '这是一条成功的提示消息',
//   type: 'success',
//   duration: 2 * 1000
// })
const cart = {
  state: {
    cartNums: {} // 商品信息
  },
  mutations: {
    CAERNUMS: (state, dataset) => {
      state.cartNums = dataset
    }
  },
  actions: {
    // 获取购物车数量
    setCartItemNumFn({ commit }, dataset) {
      return new Promise((resolve, reject) => {
        getCartTotalNum().then(res => {
          const data = res.data
          let totalNum
          if (data.status_code === 200) {
            totalNum = data.data.total_num
          } else {
            totalNum = 0
          }
          commit('CAERNUMS', totalNum)
          resolve(res)
        }).catch(error => {
          reject(error)
        })
      })
    }
  }
}

export default cart
